<template>
  <n-modal-provider>
    <div class="home-view">
      <!-- 员工奖励按钮 -->
      <div class="employee-rewards">
        <EmployeeRewards v-if="giftSettings && giftSettings.isOpen" :settings="giftSettings" />
      </div>
    </div>
  </n-modal-provider>
</template>

<script setup lang="ts">
import { NModalProvider } from 'naive-ui'
import EmployeeRewards from '@/views/EmployeeRewards.vue'
import { get } from '@/utils/common/request'
import { useEnvStore } from '@/store'


const envStore = useEnvStore()
// 初始为 null；一旦赋值则视为“已有值”，不再请求
const giftSettings = ref<any>(null)

// 仅监听 placeInfo：就绪后拉取礼品配置
watchEffect(() => {
  const place = envStore.placeInfo
  // 若 giftSettings 已有值（不为 null），则不再请求
  if (!place || giftSettings.value !== null) return
  get('/marketing-server/client/giftRewarding/findGiftConfigByPlaceId').then((res: any) => {
    const cfg = res?.data?.obj
    giftSettings.value = cfg || {}
  })
})

</script>

<style scoped>
.home-view {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.employee-rewards {
  position: absolute;
  right: 30px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
}

.home-content {
  text-align: center;
  padding: 2rem;
  border-radius: 12px;
  backdrop-filter: blur(20px);
  background-color: #fff;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.home-content h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  color: #333;
}

.home-content p {
  font-size: 1.2rem;
  color: #666;
}
</style>